Logic
CSE 16: Applied Discrete Mathematics
Instructor: Owen Arden
Winter 2023
The search for truth
How do we know when something is true?
Logic
- Given a premise, we want to reach a
valid conclusion.
- In other words, we want to derive new facts using facts we already
know.
- We want to make an argument supporting our
conclusion without resorting to:
- Our reputation or expertise
- How many other people agree
- Intimidation
Origins
Logic is one of the oldest intellectual disciplines, dating back to
Aristotle
Aristotle’s logic focuses on the idea of
deduction.
- Deduction (as defined by Aristotle):
-
A statement where, given certain assumptions, something different
from these assumptions is also necessarily true.
Origins
Subject : The objects we talk about in a
statement
Predicate : What we say about the
subject
Syllogism : Three statements where the
subject of the first is the predicate of the
second, and the third statement is implied by the first
two.
Origins
- All men are mortal
- Socrates is a man
- Socrates is mortal
Origins
- All men are mortal
- Socrates is a man
- Socrates is mortal
Proposition : A statement that is either
true or false.
Modern logic
In 1879 Gottlob Frege’s publishes Begriffsschrift
- Roughly translated as: “Concept Writing”.
Frege introduces formal notation, some still used ().
Defines a propositional calculus in terms of
- 9 axioms (statements assumed to be true)
- 3 inference rules (rules that create new statements
from existing ones)
Propositional calculus
p := "You are a bird."
q := "You have wings."
Compound statements:
- If you are a bird, you have wings:
- You cannot be a bird and not have wings:
- But bats have wings and are not birds! Is this a
counterexample?
How do we prove is false?
p := "??? is a bird."
q := "??? has wings."
- A counter example to requires to be true
and to be false: .
- In other words, is there a bird without wings?
- According to birds.cornell.edu,
all birds have two wings, so we probably won’t find a
counterexample…
- …without a time machine. Moa’s, the only known
wingless bird went extinct ~500 years ago.
![]()
is not !!!
p := "??? is a bird."
q := "??? has wings."
- Bats are not birds, but have wings:
- To contradict , we would need .
-
“If you are a bird, you
have wings.”
-
“If you have wings, you are
a bird.”
- Bats are a counterexample to
, but
not .
Examples from Alice in
Wonderland
“I say what I mean.”
“I see what I eat.”
“I like what I get.”
“I breathe when I sleep.”
“I mean what I say.”
“I eat what I see.”
“I get what I like.”
“I sleep when I breathe.”
![]()
What would Bertie do?
Is this inference correct?
- All X are Y
- Some Y are Z
- Therefore, some X are Z
- Try X=Toyotas, Y=Japanese cars, and Z=made in
America
- All Toyotas are Japanese cars
- Some Japanese cars are made in America
- Therefore, some Toyotas are made in America
- Now try X=Toyotas, Y=cars, and Z=Fiats
- All Toyotas are cars
- Some cars are Fiats
- Therefore, some Toyotas are Fiats
What would Bertie do?
Is this
inference correct? No! This rule is
unsound!!
- All X are Y
- Some X are Z
- Therefore, some X are Z
- Try X=Toyotas, Y=Japanese cars, and Z=made in America
- All Toyotas are Japanese cars
- Some Japanese cars are made in America
- Therefore, some Toyotas are made in America
- Now try X=Toyotas, Y=cars, and Z=Fiats
- All Toyotas are cars
- Some cars are Fiats
- Therefore, some Toyotas are Fiats
![]()
Proofs are
truth-preserving arguments
We need to create new propositions from given
facts.
A sound rule of inference should only
create true conclusions.
A proof, given a set of premises, is just a
sequence of sentences where each element is
- A premise, OR
- The result of applying a sound rule of inference to
earlier members in the sequence
- Once the desired conclusion is added to the
sequence, the proof is complete!
Axioms : Propositions that you assume to be
true. Ideally, truths that are self-evident.
Rules of inference : Rules that create new
propositions from axioms or other inferred propositions.
Some special names for inferred (proven to be true) propositions:
- Lemma: A statement used to prove other statements
- Theorem: A new statement that is “important”
- Corollary: A special case of a theorem that is useful/popular
Using previously proven Lemmas, Theorems, and Corollaries (plus
axioms), new results can be proven with rules of inference.
Outline
- The Language of Propositions
- Applications
- Translating English Sentences
- System Specifications
- Logic Puzzles
- Logic Circuits
- Logical Equivalences
- Important Equivalences
- Showing Equivalence
- Satisfiability
Proposition or Not?
A proposition is a declarative sentence that is either true
or false.
Sentence:
- Trenton is the capital of New Jersey.
- The Moon is made of green cheese.
Propositional Logic
Notation for constructing propositions
- The proposition that is always
true:
- The proposition that is always
false:
- Propositional variables: p, q, r, s
- Logical connectives
- Used to construct compound propositions
- Negation
- Conjunction
- Disjunction
- Implication
- Biconditional
Truth tables
We can specify the meaning of connectives using truth
tables.
Truth table: A table with the truth-values of
a logical formula for each combination of values of its propositional
variables.
Truth tables were invented by Ludwig Wittgenstein, a student of
Russell’s…
who once alledgedly threatened Karl Popper (another philosopher) with
a fireplace poker.
![]()
Negation
The negation of a proposition is written and has truth table:
Example: If
denotes “The earth is round.”, then denotes “It is not the case that the earth is round.”, or
just “The earth is not round.”
Conjunction
The conjunction of propositions and is written and has truth table:
Example: If
denotes “I am at home.” and
denotes “It is raining.” then denotes “I am home, and it is raining.”
Disjunction
The disjunction of propositions and is written and has truth table:
Example: If
denotes “I am at home.” and
denotes “It is raining.” then denotes “I am home, or it is raining.”
English “or” vs logical “or”
In English, “or” has two distinct meanings.
- Inclusive Or : “Students who have taken MATH 19A or
MATH 19B may take this class.”
- Meaning: Students should have taken one of the pre-reqs, but may
have taken both.
- Exclusive Or : “The entree comes with soup or
salad.”
- Meaning: You can get a soup or a salad with the entree, but not
both.
Which kind of “or” is
disjunction? ()
Exclusive or (XOr)
The exclusive or of propositions and is written and has truth table:
Example: If
denotes “I choose the soup.” and
denotes “I choose the salad.” then denotes “I choose the soup or I choose the salad.”
Conditional reasoning
- Assume the following premise is true:
- “If I study hard, I will pass CSE 16.”
- Can we infer
- “If I passed CSE 16, then I studied hard.” ?
Conditional reasoning
- Assume the following premise is true:
- “If the company is convicted of fraud, it will go bankrupt.”
- Suppose the company goes bankrupt. Can we infer the company was
convicted of fraud?
Implication
The implication of proposition with respect to is written and has truth table:
Example: If
denotes “I am at home.” and
denotes “It is raining.” then denotes “If I am home, then it is raining.”
If I am at home and it is raining, then is
true.
If I am at home and it is not raining, then
is
false.
- What if I am not at home?
Implication
The implication of proposition with respect to is written and has truth table:
Example: If then .
- More formally, let and . Is true for any ?
- What if ?
is false and is false.
- What if ?
is false and is true.
Implication
The implication of proposition with respect to is written and has truth table:
Example: If then .
- We say that is true since you will never
find a value of such that and .
- Therefore in the truth table, whenever is false, is true, regardless of the value
of .
Implication causation
- “If I use the power of Grayskull to make it true, then .”
- Intuitively, this statement seems false, or at least fishy.
- is true by the laws of
math, not by the power of Grayskull.
- Mathematically, the statement is true.
- The requirement is to prove the conclusion true, whether we use the
premise or not is irrelevant.
- So say the line, He-Man: “By the power of Grayskull, 1+1=2!”
Implication as a promise
- You could view the logical conditional as an obligation.
- “If I am elected, then I will fund affordable housing.”
- If the politician is elected and does not fund affordable
housing, then they have broken their campaign pledge.
- In this case (“I
am elected.”), but (“I
did not fund affordable housing.”).
- If the politician is not elected then no promises
are broken.
Understanding implication
Recognizing implication
- All of these are ways of expressing :
if
then
if ,
, unless
if
whenever
follows from
implies
only if
when
is sufficient
for
is necessary
for
a sufficient condition for is
a necessary condition for is
Recognizing implication
- Why does he want to know when
?
Biconditional
If and are propositions, the we can form the
biconditional proposition , read as “ if and only if ”, with truth table:
Example: If
denotes “I am at home.” and
denotes “It is raining.” then denotes “I am home if and only if it is
raining.”
Recognizing biconditionals
if and only
if
is necessary and
sufficient for
if
then ,
and conversely
iff
Should you honk if
their light is green?
![]()
- If you honk, then you love formal logic.
- If you love formal logic, then you honk.
Tautologies and
contradictions
Tautology: a proposition that is always
true.
Contradiction: a proposition that is always
false.
Converse, inverse,
contrapositive
Converse: The converse of is .
Inverse: The inverse of is .
Contrapositive: The contrapositive of
is .
Converse, inverse,
contrapositive
Notice anything about that last column (the contrapositive)?
It had the same values as !
That means the contrapositive of is logically equivalent!
Truth tables are a good way to show logical equivalence (and
non-equivalence). Which of the below formulas are
equivalent?
Logical equivalence
Logically equivalent: Two propositions and are logically equivalent iff
is a
tautology.
We write equivalence as or where and are compound propositions.
If and ’s truth tables agree, they are
equivalent!
Proving De Morgan’s Second
Law
Laws of propositional logic
We fully can axiomatize (specify the axioms / assumptions
of) propositional logic using similar equivalences.
Idempotence |
|
|
Associativity |
|
|
Commutativity |
|
|
Distributivity |
|
|
Identity |
|
|
Domination |
|
|
Dbl negation |
|
|
Complement |
|
|
De Morgans |
|
|
Absorption |
|
|
Conditional identity |
|
|
Predicates and quantifiers
Generalizing
relationships between propositions
Propositional example:
- If Jack knows Jill, then Jill knows Jack.
- Jack knows Jill.
- Does Jill know Jack?
- What about other people?
- If Calvin knows Hobbes, then Hobbes knows
Calvin.
- If Charlie knows Lucy, then Lucy knows
Charlie.
- …
How can we say “If one person knows another, then the second person
knows the first.” without needing a proposition for every
person?
Predicate logic
Predicate logic adds new features to propositional logic:
Variables: , ,
Predicates: “ is even”,
“ = z^n”
Propositional functions: ,
Quantifiers:
“for all”,
“there exists”
Defining propositional
functions
Predicate: A logical statement whose truth
value depends on one or more variables.
Domain: The set of all possible values for
a variable.
Propositional function: A generalization
of a proposition defined by a predicate which becomes a proposition
when the predicate’s variables are replaced by elements from their
domain.
Defining propositional
functions
Example: Let the domain of be the integers.
- is false.
- is true.
- is true.
- is not a proposition.
- is not a proposition.
Quantifiers
Quantifiers let us talk about all or some
(i.e., at least one) of the elements in a variable’s
domain.
Around since Frege, but notation and popularization due mostly to his
contemporary Peirce.
Charles Peirce (1839-1914)
Universal quantification:
Universal quantification: reads “For all ,
of .” and asserts that is true for every
in the domain.
Example: Let the domain of be the integers.
Existential quantification:
Existential quantification: reads “There exists an
such that of .” and asserts that is true for at least
one in the domain.
Example: Let the domain of be the integers.
Uniqueness quantification:
Uniqueness quantification: reads “There is a unique
such that of .” and asserts that is true for one and only
one in the domain.
Example: Let the domain of be the integers.
Uniqueness quantification:
Uniqueness quantification: reads “There is a unique
such that of .” and asserts that is true for one and only
one in the domain.
Uniqueness is actually derivable in terms of , , and equality ().
Variable scope
Variables have a scope just like in a programming
language.
In predicate logic, the scope of a variable is defined by a
quantifier.
Occurrences of a variable within a quantifier’s scope are called
bound. Occurrences which are not bound are called
free.
Example: Here is free and
is bound.
Quantifier intuition
One way to understand quantifiers is to think about the
finite case.
- Let’s assume the domain of is finite and consider how we might
evaluate the truth value of
- Loop through all possible values of .
- If is
true for each value of , then is
true.
- Otherwise is false.
- Similar to a list of ANDs, one for each value of
Quantifier intuition
One way to understand quantifiers is to think about the
finite case.
- Let’s assume the domain of is finite and consider how we might
evaluate the truth value of
- Loop through all possible values of .
- If is
false for each value of , then is
false.
- Otherwise is true.
- Similar to a list of ORs, one for each value of
Negating quantified
statements
Notice how our algorithms seemed similar, but opposite to each other?
These equivalences make that explicit:
To get why, think about De Morgan’s Law:
Recognizing quantification
- “Every student in the class has taken a Python course.”
- Domain?
- Formal statement?
Define to be “ has taken a Python course.” where the
domain of is the set of students
in the class.
Negating the statement gives “Is it not the case that every student
in the class has taken Python.”
Or put another way, “There is a student in the class who has not
taken Python.”
Recognizing quantification
- “There is a student in the class who has taken a Python
course.”
Negating the statement gives “it not the case that there is a student
in the class who has taken a Python course.”
Or put another way, “Every student in the class has not taken a
Python course.”
Nested quantifiers
Nested quantifiers are often necessary to express concepts.
Example: “Every real number has an inverse.”
- Propositional functions can also be nested:
Order of quantifiers
Is the same
as ?
Consider is a soul
mate of .
- Translate to English:
- “There exists a that is the soulmate of every .”
- Translate to English:
- “For every
there exists a that is the
soulmate of .”
- Translate to English:
- “For every
there exists a unique that is the soulmate of .”
Order of quantifiers
Examples:
- Let , where the domain of
and is the real numbers.
- Let , where the domain of
and is the real numbers.
More quantifier order
practice
Let
where and are real numbers.
More quantifier order
practice
Let where
and are real numbers.
Recognizing nested
quantification
|
is true for every pair . |
There is at least on pair for which is false. |
|
For every there is a for which is true. |
There is an such that is false for every . |
|
There is an for which is true for every . |
For every there is a for which is false. |
|
There is a pair for which is true. |
is false for every pair |
Negating nested
quantification
Recall De Morgan’s laws for quantifiers:
Let’s apply these laws to a statement with nested quantifiers.
- Write a statement for “There does not exist a
person who has taken a flight on every airline in the world.”
- Let
“ has taken flight ”, where has domain people, and has domain flights.
- Let
“Flight is operated by .”, where has domain airlines, and has domain flights.
Negating nested
quantification
Now let’s use De Morgan’s Laws to move the negation as far “inwards”
as possible.
by De Morgan’s
for
by De Morgan’s
for
by De Morgan’s
for
by De Morgan’s
for
“For every person there is an airline such that for all flights,
the person has not taken that flight or that flight is not on that
airline.”
More translation practice
Example:
Let have domain of the
students in your school.
Let “ has a computer.”
Let “ and are friends.”
- Translate:
- Answer: “Every student in your
school has a computer or has a friend who has a computer.”
- Translate:
- Answer: “There is a student with
no friends that are also friends with each other.”
More translation practice
- Example 1: “Brothers are
siblings.”
- Example 2: “Siblinghood is
symmetric.”
- Example 3: “Everybody loves
somebody.”
- Example 4: “There is someone who
is loved by everyone.”
- Example 5: “There is someone who
loves someone.”
- Example 6: “Everyone loves
themselves”
Translating mathematical
statements
Example: Translate “The sum of two positive integers
is always positive” into an expression in predicate logic.
- Rewrite to make quantifiers and domains explicit:
- “For every two integers, if these integers are both
positive, then the sum of the integers is positive.”
- Rewrite to use variables and specify their domain:
- “For all positive integers and , is positive.”
- Now replace the English phrases with the
appropriate notation.
- where have domain of (all) integers.
Example from Calculus
(of infinitesimals):
Limit: Let be a function defined on some open
interval that contains the number , except possibly at itself. Then we say that the
limit of as approaches is , and we write
if for
every number
there is a number
such that
We can use quantifiers to express the definition of the limit of a
real-valued function of a real
variable at a point in its domain.
where the domain of
and is the positive reals
and the domain of is all
reals.
Reasoning about Calculus
with logic
How could we use our logical definition of limits to express that the
limit of as approaches does not exist?
- We need to say that for all real numbers ,
Reasoning about Calculus
with logic
- Quantify over all real numbers :
- Translating back to English:
- For every real number , there is a real number , such that for every
real number , there
exists a real number such that
and
.
Recap
Tautology: a proposition that is always
true.
Contradiction: a proposition that is always
false.
Logically equivalent: Two propositions and are logically equivalent,
written , iff is a tautology.
Proof technique
So far we have only proven tautologies, contradictions, and
equivalence using truth tables. This approach is not scalable.
With variables, there are
truth assignments. Worse,
truth tables cannot be used with quantifiers and infinite
sets!
Deriving new
propositions from existing ones
How can we get new conclusions from existing premises without
enumerating all truth values?
IDEA: Can we manipulate logical statements
symbolically using axioms and inference rules to obtain a proof
of the desired conclusion?
Proofs according to
Logicomix
A proof is the verification of a a mathematical
statement starting from a set of agreed-upon first
principles proceeding by unambiguous and unabridged
logical steps or rules of inference.
- What are agreed-upon first principles?
- Axioms or proven statements
derived from these axioms.
Theorems
Theorem: any inference obtained from
- a set of premises:
- axioms or previously proven theorems
- the rules of inference
Notation:
- (no premises,
is empty)
- Zybook style:
Zybook also calls theorems valid arguments.
Example: Hilbert’s system
- Small set of axioms and rules of inference from which all theorems
can be derived.
Three axioms:
(actually 4 originally, but one turned out to be
redundant)
One inference rule: Modus Ponens
From which all theorems of propositional logic can
be derived!
Hilbert’s Axioms are tautologies!
Can you prove it?
Prove an axiom?
Wondering how they figured out one of the axioms was redundant?
They proved it could be derived from the other axioms!
Goal: Derive using only axioms and modus ponens.
Prove an inference rule?
Show it is a valid argument (is a theorem)!
Consider this argument:
What do we need to prove to show this argument is a theorem?
In general is valid (true for all truth values of and ) if is a tautology.
Proof
Notice: Every line is either a premise, an instance
of an axiom, or the result of applying a theorem or rule (e.g., MP) to
previous line(s).
Some valid (and useful) rules
|
Modus ponens |
|
Modus tollens |
|
Addition (L) |
|
Addition (R) |
|
Simplification (L) |
|
Simplification (R) |
|
Conjunction |
|
Hypothetical syllogism |
|
Disjunctive syllogism |
|
Resolution |
Back to Aristotle
What about quantifiers?
- We can express Aristotle’s example in predicate logic as the following
argument:
or
- Is this a valid argument?
: updated to be slightly
less gender-biased
Universal Instantiation (UI)
where is from the domain of
.
Example: For the domain of all dogs, where Thornton
is a dog.
- Suppose “All dogs are cuddly.”
- Therefore, “Thornton is cuddly.”
Universal Generalization (UG)
where is an arbitrary
element from the domain of .
This is often left implicit in proofs when a statement has been
proven in terms of an arbitrary element.
Example: Consider an arbitrary natural number .
- (by definition)
- Therefore,
Existential Instantiation
(EI)
for some element in the domain
of
(but you don’t know
which one).
Example:
- “There is someone who got a ticket to Taylor Swift.”
- Let’s call them TayFan and say: “TayFan got a ticket.”
- “There is someone who got 2 tickets to Taylor
Swift.”
- Can we say “TayFan got 2 tickets.”?
- No, because it may or may not be the same
person.
- Instead we call this one TayFan2 and say “TayFan2
got 2 tickets.”
Existential Generalization
(EG)
for some element in the domain
of
(but you may or may not
know which one).
Example:
- “Michelle got tickets to Taylor Swift.”
- “Therefore, someone got tickets to Taylor Swift.”
Michelle would sometimes be called the “witness” to the existential
since her existence proves the quantified statement.
Back to Socrates’ Mortality
More practice
Example: Suppose:
- “A student in the class has not read the book.”
- “Everyone in the class passed the exam.”
Construct a valid argument (prove) that the following conclusion
follows from these premises.
Solution:
Define:
- to be “ is in the class.”
- to be “ has read the book.”
- to be “ passed the exam.”
More practice
- Formally, we wish to prove
Valid Quantifier Rules
|
is
an element in domain of |
Universal Instantiation |
|
is
an arbitrary element in domain of |
Universal Generalization |
|
is
a “fresh” name for some particular element in domain of |
Existential Instantiation |
|
is
a particular element in domain of |
Existential Generalization |